import store from '@/store';

const buttonPermEnabled = process.env.VUE_APP_BUTTON_PERM_ENABLED;

export const hasPerm = function (code) {
    if (buttonPermEnabled && buttonPermEnabled === 'true') {
        const userInfo = store.state.userInfo;

        const resultList = [];
        if (userInfo && userInfo.buttonPermissions && userInfo.buttonPermissions.length > 0) {
            userInfo.buttonPermissions.forEach((item) => {
                resultList.push(item.code);
            });
            return resultList.includes(code);
        }
        return false;
    }
    return true;
}
